﻿Public Class Formulario
    Dim estado As String
    Private Sub Formulario_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Me.CenterToScreen()
        estado_inicial()
    End Sub

    Private Sub ch_busqueda_cliente_CheckedChanged(sender As Object, e As EventArgs) Handles ch_busqueda_cliente.CheckedChanged
        If ch_busqueda_cliente.Checked = True Then
            cb_busqueda_cliente.Enabled = True
        Else
            cb_busqueda_cliente.Enabled = False
        End If
    End Sub

    Private Sub ch_busqueda_vendedor_CheckedChanged(sender As Object, e As EventArgs) Handles ch_busqueda_vendedor.CheckedChanged
        If ch_busqueda_vendedor.Checked = True Then
            cb_busqueda_vendedor.Enabled = True
        Else
            cb_busqueda_vendedor.Enabled = False
        End If

        If (ch_busqueda_cliente.Checked = True Or ch_busqueda_vendedor.Checked = True Or ch_busqueda_fecha.Checked = True Or ch_busqueda_cotizacion.Checked = True) Then
        Else
        End If
    End Sub

    Private Sub ch_busqueda_fecha_CheckedChanged(sender As Object, e As EventArgs) Handles ch_busqueda_fecha.CheckedChanged
        If ch_busqueda_fecha.Checked = True Then
            dt_busqueda_desde.Enabled = True
            dt_busqueda_hasta.Enabled = True
        Else
            dt_busqueda_desde.Enabled = False
            dt_busqueda_hasta.Enabled = False
        End If
    End Sub

    Private Sub ch_busqueda_cotizacion_CheckedChanged(sender As Object, e As EventArgs) Handles ch_busqueda_cotizacion.CheckedChanged
        If ch_busqueda_cotizacion.Checked = True Then
            tx_busqueda_cotizacion.Enabled = True
        Else
            tx_busqueda_cotizacion.Enabled = False
        End If
    End Sub

#Region "estados"
    Private Sub estado_inicial()
        estado = "estado_inicial"
        bt_nuevo.Visible = True
        panel_grilla.Size = New Size(885, 540)
        grilla_maestro.Size = New Size(870, 530)
        panel_busqueda.Visible = True
        panel_grilla.Visible = True
        panel_formulario.Visible = False
        panel_guardar_cancelar.Visible = False
        panel_opciones.Visible = False
        bt_nuevo.Focus()
        Me.bt_nuevo.Select()
        error_cotizacion.Clear()
    End Sub
    Private Sub estado_nuevo()
        estado = "estado_nuevo"
        habilitar_controles_formulario()
        cb_estado.SelectedIndex = 0
        panel_busqueda.Visible = False
        panel_grilla.Visible = False
        panel_formulario.Visible = True
        panel_guardar_cancelar.Visible = True
        panel_opciones.Visible = False
        tx_cotizacion_a.Focus()
        bt_nuevo.Visible = False
    End Sub
    Private Sub estado_seleccion()
        panel_grilla.Visible = False
        panel_busqueda.Visible = False
        panel_opciones.Visible = True
        panel_formulario.Visible = True
        panel_guardar_cancelar.Visible = False
        bt_nuevo.Visible = False
        deshabilitar_controles_formulario()
    End Sub
    Private Sub estado_modificacion()
        estado = "modificacion"
        habilitar_controles_formulario()
        panel_guardar_cancelar.Visible = True
        panel_opciones.Visible = False
    End Sub

    Private Sub deshabilitar_controles_formulario()
        tx_cotizacion_a.Enabled = False
        tx_cotizacion_b.Enabled = False
        cb_estado.Enabled = False
        dt_fecha.Enabled = False
        tx_cliente_a.Enabled = False
        tx_cliente_b.Enabled = False
        bt_traer_cliente.Enabled = False
        dt_vigencia.Enabled = False
        tx_cond_venta.Enabled = False
        cb_vendedor.Enabled = False
        tx_bonificacion.Enabled = False
        tx_lista_precios.Enabled = False
        tx_codigo_transporte.Enabled = False
        tx_moneda_a.Enabled = False
        tx_moneda_b.Enabled = False
        tx_observaciones.Enabled = False
    End Sub

    Private Sub habilitar_controles_formulario()
        tx_cotizacion_a.Enabled = True
        tx_cotizacion_b.Enabled = True
        cb_estado.Enabled = True
        dt_fecha.Enabled = True
        tx_cliente_a.Enabled = True
        tx_cliente_b.Enabled = True
        bt_traer_cliente.Enabled = True
        dt_vigencia.Enabled = True
        tx_cond_venta.Enabled = True
        cb_vendedor.Enabled = True
        tx_bonificacion.Enabled = True
        tx_lista_precios.Enabled = True
        tx_codigo_transporte.Enabled = True
        tx_moneda_a.Enabled = True
        tx_moneda_b.Enabled = True
        tx_observaciones.Enabled = True
    End Sub


#End Region


    Private Sub bt_nuevo_Click(sender As Object, e As EventArgs) Handles bt_nuevo.Click
        Me.estado_nuevo()
    End Sub

    Private Sub bt_cancelar_Click(sender As Object, e As EventArgs) Handles bt_cancelar.Click
        If estado = "modificacion" Then
            If MessageBox.Show("Desea cancelar la modificacion?", "Atencion", MessageBoxButtons.YesNo, MessageBoxIcon.Stop) = Windows.Forms.DialogResult.Yes Then
                Me.estado_seleccion()
            End If
        ElseIf estado = "estado_nuevo" Then
            If MessageBox.Show("Desea cancelar la carga de la cotización?", "Atención", MessageBoxButtons.YesNo, MessageBoxIcon.Stop) = Windows.Forms.DialogResult.Yes Then
                estado_inicial()
            Else
                tx_cotizacion_a.Focus()
            End If
        End If
    End Sub

#Region "key_press"
    Private Sub tx_cotizacion_a_KeyPress(sender As Object, e As KeyPressEventArgs) Handles tx_cotizacion_a.KeyPress
        If Asc(e.KeyChar) = 13 Then
            tx_cotizacion_b.Focus()
        End If
    End Sub
    Private Sub tx_cotizacion_b_KeyPress(sender As Object, e As KeyPressEventArgs) Handles tx_cotizacion_b.KeyPress
        If Asc(e.KeyChar) = 13 Then
            cb_estado.Focus()
        End If
    End Sub
    Private Sub cb_estado_KeyPress(sender As Object, e As KeyPressEventArgs) Handles cb_estado.KeyPress
        If Asc(e.KeyChar) = 13 Then
            dt_fecha.Focus()
        End If
    End Sub
    Private Sub dt_fecha_KeyPress(sender As Object, e As KeyPressEventArgs) Handles dt_fecha.KeyPress
        If Asc(e.KeyChar) = 13 Then
            bt_traer_cliente.Focus()
        End If
    End Sub
    Private Sub bt_traer_cliente_Click(sender As Object, e As EventArgs) Handles bt_traer_cliente.Click
        Me.tx_cliente_b.Focus()
    End Sub
    Private Sub tx_cliente_b_KeyPress(sender As Object, e As KeyPressEventArgs) Handles tx_cliente_b.KeyPress
        If Asc(e.KeyChar) = 13 Then
            dt_vigencia.Focus()
        End If
    End Sub
    Private Sub dt_vigencia_KeyPress(sender As Object, e As KeyPressEventArgs) Handles dt_vigencia.KeyPress
        If Asc(e.KeyChar) = 13 Then
            tx_cond_venta.Focus()
        End If
    End Sub
    Private Sub tx_cond_venta_KeyPress(sender As Object, e As KeyPressEventArgs) Handles tx_cond_venta.KeyPress
        If Asc(e.KeyChar) = 13 Then
            cb_vendedor.Focus()
        End If
    End Sub
    Private Sub cb_vendedor_KeyPress(sender As Object, e As KeyPressEventArgs) Handles cb_vendedor.KeyPress
        If Asc(e.KeyChar) = 13 Then
            tx_bonificacion.Focus()
        End If
    End Sub
    Private Sub tx_bonificacion_KeyPress(sender As Object, e As KeyPressEventArgs) Handles tx_bonificacion.KeyPress
        If Asc(e.KeyChar) = 13 Then
            tx_lista_precios.Focus()
        End If
    End Sub
    Private Sub tx_lista_precios_KeyPress(sender As Object, e As KeyPressEventArgs) Handles tx_lista_precios.KeyPress
        If Asc(e.KeyChar) = 13 Then
            tx_codigo_transporte.Focus()
        End If
    End Sub
    Private Sub tx_codigo_transporte_KeyPress(sender As Object, e As KeyPressEventArgs) Handles tx_codigo_transporte.KeyPress
        If Asc(e.KeyChar) = 13 Then
            tx_moneda_a.Focus()
        End If
    End Sub
    Private Sub tx_moneda_a_KeyPress(sender As Object, e As KeyPressEventArgs) Handles tx_moneda_a.KeyPress
        If Asc(e.KeyChar) = 13 Then
            tx_moneda_b.Focus()
        End If
    End Sub
#End Region

#Region "Control campos vacios"
    Private Sub control_campos_vacios()
        If tx_cotizacion_b.Text = "" Then
            error_cotizacion.SetError(tx_cotizacion_b, "Error, campo vacío")
        Else
            ''  ErrorProvider1.Clear()
        End If
        If tx_cotizacion_a.Text = "" Then
            error_cotizacion.SetError(tx_cotizacion_a, "Error, campo vacío")
        Else
            'ErrorProvider1.Clear()
        End If
        If cb_estado.Text = "" Then
            error_cotizacion.SetError(cb_estado, "Error, campo vacío")
        Else
            '  ErrorProvider1.Clear()
        End If
        If dt_fecha.Text = "" Then
            error_cotizacion.SetError(dt_fecha, "Error, campo vacío")
        Else
            '  ErrorProvider1.Clear()
        End If
        If tx_cliente_a.Text = "" Then
            error_cotizacion.SetError(tx_cliente_a, "Error, campo vacío")
        Else
            '   ErrorProvider1.Clear()
        End If
        If tx_cliente_b.Text = "" Then
            error_cotizacion.SetError(tx_cliente_b, "Error, campo vacío")
        Else
            '   ErrorProvider1.Clear()
        End If
        If dt_vigencia.Text = "" Then
            error_cotizacion.SetError(dt_vigencia, "Error, campo vacío")
        Else
            '   ErrorProvider1.Clear()
        End If
        If tx_cond_venta.Text = "" Then
            error_cotizacion.SetError(tx_cond_venta, "Error, campo vacío")
        Else
            '   ErrorProvider1.Clear()
        End If
        If cb_vendedor.Text = "" Then
            error_cotizacion.SetError(cb_vendedor, "Error, campo vacío")
        Else
            '   ErrorProvider1.Clear()
        End If
        If tx_bonificacion.Text = "" Then
            error_cotizacion.SetError(tx_bonificacion, "Error, campo vacío")
        Else
            '    ErrorProvider1.Clear()
        End If
        If tx_lista_precios.Text = "" Then
            error_cotizacion.SetError(tx_lista_precios, "Error, campo vacío")
        Else
            '   ErrorProvider1.Clear()
        End If
        If tx_codigo_transporte.Text = "" Then
            error_cotizacion.SetError(tx_codigo_transporte, "Error, campo vacío")
        Else
            '   ErrorProvider1.Clear()
        End If
        If tx_moneda_a.Text = "" Then
            error_cotizacion.SetError(tx_moneda_a, "Error, campo vacío")
        Else
            '   ErrorProvider1.Clear()
        End If
        If tx_moneda_b.Text = "" Then
            error_cotizacion.SetError(tx_moneda_b, "Error, campo vacío")
        Else
            '    ErrorProvider1.Clear()
        End If
        If tx_observaciones.Text = "" Then
            error_cotizacion.SetError(tx_observaciones, "Error, campo vacío")
        Else
            '    ErrorProvider1.Clear()
        End If
    End Sub
#End Region


    Private Sub bt_guardar_Click(sender As Object, e As EventArgs) Handles bt_guardar.Click
        control_campos_vacios()

        Try

        Catch ex As Exception
            ex.ToString()
        End Try
    End Sub

    Private Sub tx_cotizacion_a_LostFocus(sender As Object, e As EventArgs) Handles tx_cotizacion_a.LostFocus
        If tx_cotizacion_a.Text <> "" Then

        End If
    End Sub


    Private Sub bt_eliminar_Click(sender As Object, e As EventArgs) Handles bt_eliminar.Click

    End Sub

    Private Sub bt_modificar_Click(sender As Object, e As EventArgs) Handles bt_modificar.Click
        estado_modificacion()
    End Sub

    Private Sub bt_imprimir_Click(sender As Object, e As EventArgs) Handles bt_imprimir.Click

    End Sub

    Private Sub bt_copiar_Click(sender As Object, e As EventArgs) Handles bt_copiar.Click

    End Sub

    Private Sub bt_pantalla_inicial_Click(sender As Object, e As EventArgs) Handles bt_pantalla_inicial.Click
        estado_inicial()
    End Sub

    Private Sub grilla_maestro_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles grilla_maestro.CellContentClick
        estado_seleccion()
    End Sub
End Class
